<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class PointBag extends Model
{
    protected $fillable = ['name',
        'description',
        'image',
        'sort_num',
        'point',
        'growing_coffee',
        'free_coupon',
        'discount_coupon'
        ];

    protected $casts = [
        'growing_coffee' => 'json',
        'free_coupon' => 'json',
        'discount_coupon' => 'json',
    ];

    public function getGrowingCoffee()
    {
        return (double)random_int($this->body['growingCoffee']['min']*100, $this->body['growingCoffee']['max']*100)/100;
    }

    public function getCoupon()
    {
        return [
            'name' => $this->body['name'],
            'type' => $this->body['type'],
            'expired_at' => Carbon::now()->addDay(7)->toDateString(),
            'discount' => $this->body['discount'],
            'is_used' => false,
        ];
    }
}
